﻿using System;
using System.Collections.Generic;
using System.Text;

namespace KnBinarySerializer.Brick
{
    internal class BoolFormatterByteFormatter : IFormatter
    {
        public Type GetHandleType()
        {
            return typeof(bool);
        }
        public bool IsFixLen()
        {
            return true;
        }
        public byte GetKey()
        {
            return 11;
        }

        public object ReadBytes(BianaySerializeManager content, int maxLen, Type type)
        {
            byte bit = content.ReadByte();
            return (bit == 0) ? false : true;
        }

        public int WriteBytes(BianaySerializeManager serial, object obj)
        {
            bool isTrue = (bool)obj;
            if (isTrue)
                serial.Write((byte)1);
            else
                serial.Write((byte)0);
            return 1;
        }
    }
}
